package com.ruoyi.lxy.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.ruoyi.lxy.domain.HwmxDomain;
import com.ruoyi.lxy.service.LxyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

//@Configuration
//@EnableScheduling
@Component("lxyTask")
public class JsonFormTask {

    @Autowired
    private LxyService lxyService;

//    @Scheduled(cron = "0 0/20 * * * ?")
    public void json2Local() throws InterruptedException {


        List<String> hwmx = lxyService.getHwmx();
        lxyService.deleteSon();
        for (String temp:hwmx
             ) {
            if(temp != null){
                final List<Map<String,String>> lists = (List<Map<String,String>>) JSONUtils.parse(temp);

                for (Map<String,String> map:lists
                     ) {
                    HwmxDomain hwmxDomain = new HwmxDomain(
                            map.get("_id"),
                            map.get("hw_pici"),
                            map.get("hw_beizhu"),
                            map.get("hw_huowei"),
                            String.valueOf(map.get("hw_shuliang")),
                            map.get("hw_guigexinghao"),
                            map.get("hw_chanpinmingcheng"),
                            map.get("zhiliangwenti"),
                            map.get("quyu"),
                            0

                    );
                    lxyService.saveOrUpdate(hwmxDomain);
//                    System.out.println(map.get("hwHuowei"));
                }
            }

        }
    }
    public static void main(String[] args) throws InterruptedException {
        JsonFormTask temp = new JsonFormTask();
        temp.json2Local();
    }
}
